class Solution {
public:
    double pow(double x, int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        double y = x;
        double result = 1.0;
        bool sign = n < 0 ? true : false;

        if (n < 0) {
            n = -n;
        }
        while (n > 0) {
            if (n & 1) {
                result *= y;
            }
            y *= y;
            n >>= 1;

        }
        return sign ? 1.0 / result : result;

    }
};